<template>
  <div>
    <!-- <a-tree-select :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }" :value="value1" :treeData="treeData" :disabled="isDisabled"></a-tree-select> -->
    <a-input :value="value" :disabled="isDisabled"/>
  </div>
</template>

<script>
// import { getdepartment } from '@/api/createjobs'
// import { getDepartmentLazyChildren } from '@/api/userManagement'
const treeData = [
  // {
  //   title: '全部',
  //   value: '0-0',
  //   key: '0-0',
  //   // children: [],
  //   isShow: true
  // }
]
export default {
  name: 'Department',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: ['value', 'required', 'isReadOnlyPage', 'isDisabled'],
  data () {
    return {
      changeDepartment: '',
      treeDefaultExpandAll: false,
      treeData
    }
  },
  computed: {
    strValue () {
      console.log(this.value)
      if (!this.value) {
        return ''
      }
      if (this.value.name instanceof Array) {
        return this.value.name[0]
      } else {
        return this.value.name
      }
    },
    value1 () {
      console.log(this.value)
      if (!this.value) {
        return ''
      }
      return this.value.name + ''
      // this.$emit('creatDepartmentId', value)
    }
  },
  mounted () {
    // this.userTemplate()
  },
  methods: {
    onchange (val, label, extra) {
      console.log(val, label, extra)
      let obj = {}
      // console.log(`Department: { val: ${JSON.stringify(val)}, label: ${JSON.stringify(label)}}`, extra)
      if (!val) {
        obj = ''
      } else {
        obj = { id: extra.triggerNode.dataRef.id, name: extra.triggerNode.dataRef.title }
      }
      console.log(obj)
      this.$emit('change', obj)
      this.$emit('ckeckedKeys', 'department')
    },
    onLoadData (treeNode) {
      // return new Promise(resolve => {
      //   if (treeNode.dataRef.children) {
      //     resolve()
      //     return
      //   }
      //   getDepartmentLazyChildren({
      //     id: treeNode.dataRef.id
      //   }).then(res => {
      //     if (res.code === 200) {
      //       const data = res.data
      //       treeNode.dataRef.children = data.map((item, index) => {
      //         return {
      //           title: item.name,
      //           value: `${treeNode.eventKey}-${index}`,
      //           key: `${treeNode.eventKey}-${index}`,
      //           id: item.id,
      //           isLeaf: !item.childrenFlag
      //         }
      //       })
      //     }
      //     this.treeData = [...this.treeData]
      //     resolve()
      //   })
      // })
    },
    userTemplate () {
      // getdepartment().then(response => {
      //   if (response.data && response.data[0].hasOwnProperty('childrenFlag')) {
      //     this.treeData = response.data.map((item, index) => {
      //       return { title: item.name, value: index + '', key: index, id: item.id, isLeaf: !item.childrenFlag }
      //     })
      //   } else {
      //     this.onLoadData = null // onLoadData会一直执行
      //     this.treeDefaultExpandAll = true
      //     this.treeData = resizeTree(response.data)
      //   }
      // }).catch(error => {
      //   return error.data
      // })
    }
  }
}
// function resizeTree (arr, key = 0) {
//   if (!Array.isArray(arr)) return
//   return arr.map((item, index) => {
//     let treekey = `${key}-${index}`
//     return { title: item.name, value: item.id, key: item.id, id: item.id, children: resizeTree(item.children, treekey) }
//   })
// }
</script>
